package com.imooc.imoocbilibili.controller;

import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.imooc.imoocbilibili.entity.Tag;
import com.imooc.imoocbilibili.service.TagService;
import com.imooc.imoocbilibili.utils.R;


/**
 * 标签表
 *
 * @author jl
 * @since 2022-04-10 21:13:43
 */
@RestController
@RequestMapping("imoocbilibili/tag")
@RequiredArgsConstructor
public class TagController {

    private final TagService tagService;

    /**
     * 分页查询标签表
     */
    @GetMapping("/list")
    public R list(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        return R.ok(tagService.queryPage(pageNo, pageSize));
    }


    /**
     * 根据主键查询标签表
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        Tag tag =tagService.getById(id);
        return R.ok(tag);
    }

    /**
     * 新增标签表
     */
    @PostMapping("/save")
    public R save(@RequestBody Tag tag) {
            tagService.save(tag);
        return R.ok();
    }

    /**
     * 修改标签表
     */
    @PutMapping("/update")
    public R update(@RequestBody Tag tag) {
            tagService.updateById(tag);
        return R.ok();
    }

    /**
     * 删除标签表
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
            tagService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
